package com.salt.modules.sys.feign;

import com.salt.common.constant.Common;
import com.salt.core.web.BaseController;
import com.salt.modules.sys.entity.MultiTenant;
import com.salt.modules.sys.entity.User;
import com.salt.modules.sys.service.MultiTenantService;
import com.salt.modules.sys.utils.UserUtils;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description
 * @Author salt
 * @Date 2022/1/21
 * @Version 1.0.1
 */
@RestController
@AllArgsConstructor
@RequestMapping(Common.Service.SALT_ADMIN_TENANT_URL_PREFIX)
public class TenantFeignController extends BaseController {

    private final MultiTenantService multiTenantService;

    @GetMapping("find")
    public MultiTenant find() {
        MultiTenant multiTenant = multiTenantService.find(new MultiTenant(UserUtils.getUser()));
        if (multiTenant != null)
            multiTenantService.setTenantList(multiTenant);
        return multiTenant;
    }

    @PostMapping("findByUser")
    public MultiTenant findByUser(User user){
        return multiTenantService.find(new MultiTenant(user));
    }
}
